//
//  WenTiFuDaoVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/17.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "WenTiFuDaoVC.h"
#import "TCollectionViewControllelr.h"
#import "CJClassSelectedView.h"



@interface WenTiFuDaoVC ()<WenTiFuDaoNavViewDelegate,QBWTVCDelegate>
{
    CGFloat mainw;
    int currentPage;
}
@property (nonatomic, assign) BOOL Type;
@property (nonatomic, copy) NSString *banji;//班级id
@property (nonatomic, copy) NSString *riqi;//日期
@property (nonatomic, copy) NSString *keyStr;


@end

@implementation WenTiFuDaoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    currentPage = 0;
    _banji = @"0";
    _keyStr = @"";
    mainw  = MAINW;
    [self.view addSubview:self.navView];
    _navView.mainw = mainw;
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    [self addNotice];
    
    [self.view addSubview:self.mainScrollView];
    
    [_mainScrollView addSubview:self.leftView.view];
    [_mainScrollView addSubview:self.centerView.view];
    [_mainScrollView addSubview:self.rightView.view];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notictionKeyStr:) name:@"keyString" object:nil];
    
}
//接受到搜索通知。
- (void)notictionKeyStr:(NSNotification *)notification {
    NSString *str = notification.userInfo[@"keyString"];
    self.keyStr = str;
    [self scrollViewChangeButtom:self->currentPage];
}

- (WenTiFuDaoNavView *)navView{
    if (!_navView) {
        WenTiFuDaoNavView *view = [[WenTiFuDaoNavView alloc]initWithFrame:CGRectMake(0, 0, MAINW-150, 44) andArray:@[@"未回答",@"已回答",@"全部问题"]];
        view.backgroundColor = MAINBACKCOLOR;
        view.delegate = self;
        _navView = view;
    }
    return _navView;
}
- (void)scrollViewChangeButtom:(int)index{
    currentPage = index;
    self.mainScrollView.contentOffset = CGPointMake(mainw*index, 0);
    if (index == 0) {
        [self.leftView requestKeyBanJi:_banji riqi:_riqi keyStr:self.keyStr];
    } else if (index == 1) {
        [self.centerView requestDataBanjiId:_banji keyStr:self.keyStr];
    } else {
        [self.rightView requestDataBanJi:_banji keyStr:self.keyStr];
    }
}
- (WTFDWHDVC *)leftView{
    if (!_leftView) {
        WTFDWHDVC *view = [[WTFDWHDVC alloc]init];
        view.view.frame = CGRectMake(0, 0, mainw, APP_HEIGHT-84);
        _leftView = view;
    }
    return _leftView;
}
- (WTFDYHDVC *)centerView{
    if (!_centerView) {
        WTFDYHDVC *view = [[WTFDYHDVC alloc]init];
        view.view.frame = CGRectMake(mainw, 0, mainw, APP_HEIGHT-84);
        _centerView = view;
    }
    return _centerView;
}
- (QBWTVC *)rightView{
    if (!_rightView) {
        QBWTVC *view = [[QBWTVC alloc]init];
        view.view.frame = CGRectMake(mainw*2, 0, mainw, APP_HEIGHT-84);
        view.mainDelegate = self;
        _rightView = view;
    }
    return _rightView;
}
- (void)guanLiFenZuClick{
   // [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    _fenZuGuanLiView = [[ManagementeGroupVC alloc]init];
    _fenZuGuanLiView.mainw = mainw;
    _fenZuGuanLiView.Type = _Type;
    _fenZuGuanLiView.view.frame = CGRectMake(mainw, 0, mainw+20, APP_HEIGHT);
    [self.view addSubview:self.fenZuGuanLiView.view];
    [_fenZuGuanLiView.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
//    [UIView animateWithDuration:0.5 animations:^{
//        self->_fenZuGuanLiView.view.frame = CGRectMake(0, 0, self->mainw+20, APP_HEIGHT);
//    }completion:^(BOOL finished) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
//    }];
    __weak typeof(self) weakSelf = self;
    _fenZuGuanLiView.block = ^(id  _Nonnull obj) {
        [weakSelf.rightView requestDataBanJi:weakSelf.banji keyStr:@""];
    };
    
}
- (UIScrollView *)mainScrollView{
    if (!_mainScrollView) {
        UIScrollView *view = [[UIScrollView alloc]init];
        view.frame = CGRectMake(0, 44, MAINW, APP_HEIGHT-84);
        view.contentSize = CGSizeMake(MAINW*3, 0);
        view.showsHorizontalScrollIndicator = YES;
        view.showsVerticalScrollIndicator = NO;
        view.pagingEnabled = YES;
        view.scrollEnabled = NO;
        view.backgroundColor = MAINBACKCOLOR;
        _mainScrollView = view;
    }
    return _mainScrollView;
}
-(void)addNotice{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView:) name:@"ChangeCellSpaNotice" object:nil];
}
- (void)changeView:(NSNotification *)info{
    BOOL type = [[info.userInfo objectForKey:@"Type"] intValue];
    self.Type = type;
    mainw = [PublickFunctionObject currentScreenSize:type];
   // NSLog(@"大小 %f",mainw);
    _navView.mainw = mainw;
    [_navView uploadLayout];
    
    _mainScrollView.frame = CGRectMake(0, 44, mainw, APP_HEIGHT-84);
    _mainScrollView.contentOffset = CGPointMake(currentPage*mainw, 0);
    _leftView.view.frame = CGRectMake(0, 0, mainw, APP_HEIGHT-84);
    _centerView.view.frame = CGRectMake(mainw, 0, mainw, APP_HEIGHT-84);
    _rightView.view.frame = CGRectMake(mainw*2, 0, mainw, APP_HEIGHT-84);
}

- (void)riQiSelected {
    __weak typeof(self) weakSelf = self;
    [CJYearMonthSelectedView showDatePickerWithTitle:@"选择月份" minDateStr:@"2000-01" resultBlock:^(NSString *selectValue) {
        //选择完成后的操作
        //NSArray *array = [selectValue componentsSeparatedByString:@"-"];//
        weakSelf.riqi = selectValue;
         [weakSelf scrollViewChangeButtom:self->currentPage];
        
        weakSelf.navView.timeButton.bottomLabel.text = selectValue;
    }];
}

- (void)nianJiSelected {
    __weak typeof(self) weakSelf = self;
    [CJClassSelectedView showDatePickerWithTitle:@"选择班级" minDateStr:@"年级一" resultBlock:^(TeacherClassListModel * _Nonnull selectValue) {
     //   NSLog(@"输出选择的班级 %@",selectValue);
        weakSelf.banji = selectValue.id;
        [weakSelf scrollViewChangeButtom:self->currentPage];
        weakSelf.navView.nianjiButton.bottomLabel.text = selectValue.name;
        
    }];
}


- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"ChangeCellSpaNotice" object:nil];
    //移除所有观察者
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
